<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="学生姓名" prop="stuName">
        <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="学生学号" prop="stuNo">
        <el-input v-model="queryParams.stuNo" placeholder="请输入学生学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核人" prop="reviewer">
        <el-input v-model="queryParams.reviewer" placeholder="请输入审核人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核人身份" prop="reviewerIdentity">
        <el-input v-model="queryParams.reviewerIdentity" placeholder="请输入审核人身份" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核时间" prop="reviewTime">
        <el-date-picker clearable v-model="queryParams.reviewTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['routine:stuMultiLevelReview:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['routine:stuMultiLevelReview:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['routine:stuMultiLevelReview:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['routine:stuMultiLevelReview:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stuMultiLevelReviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学生姓名" align="center" prop="stuName" />
      <el-table-column label="学生学号" align="center" prop="stuNo" />
      <el-table-column label="申请原因" align="center" prop="reason" />
      <el-table-column label="审核人" align="center" prop="reviewer" />
      <el-table-column label="审核人身份" align="center" prop="reviewerIdentity" />
      <el-table-column label="审核时间" align="center" prop="reviewTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reviewTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="notes" />
      <el-table-column label="申请类型" align="center" prop="type">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.type === 0">学生证补办申请</el-tag>
          <el-tag type="warning" v-else-if="scope.row.type === 1">在校证明申请</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="reviewerStatus">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.reviewerStatus === 0">未审核</el-tag>
          <el-tag type="success" v-else-if="scope.row.reviewerStatus === 1">辅导员通过</el-tag>
          <el-tag type="success" v-else-if="scope.row.reviewerStatus === 2">学工处通过</el-tag>
          <el-tag type="danger" v-else>辅导员驳回</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['routine:stuMultiLevelReview:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['routine:stuMultiLevelReview:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改多级审核
对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生姓名" prop="stuName">
          <el-input v-model="form.stuName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="学生学号" prop="stuNo">
          <el-input v-model="form.stuNo" placeholder="请输入学生学号" />
        </el-form-item>
        <el-form-item label="申请原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核人" prop="reviewer">
          <el-input v-model="form.reviewer" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="审核人身份" prop="reviewerIdentity">
          <el-input v-model="form.reviewerIdentity" placeholder="请输入审核人身份" />
        </el-form-item>
        <el-form-item label="审核时间" prop="reviewTime">
          <el-date-picker clearable v-model="form.reviewTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="notes">
          <el-input v-model="form.notes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStuMultiLevelReview, getStuMultiLevelReview, delStuMultiLevelReview, addStuMultiLevelReview, updateStuMultiLevelReview } from "@/api/routine/stuMultiLevelReview";

export default {
  name: "StuMultiLevelReview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 多级审核表格数据
      stuMultiLevelReviewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuName: null,
        stuNo: null,
        reason: null,
        reviewer: null,
        reviewerIdentity: null,
        reviewTime: null,
        reviewerId: null,
        notes: null,
        type: null,
        reviewerStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        stuName: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" }
        ],
        stuNo: [
          { required: true, message: "学生学号不能为空", trigger: "blur" }
        ],
        reason: [
          { required: true, message: "申请原因不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询多级审核
列表 */
    getList() {
      this.loading = true;
      listStuMultiLevelReview(this.queryParams).then(response => {
        this.stuMultiLevelReviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stuName: null,
        stuNo: null,
        reason: null,
        reviewer: null,
        reviewerIdentity: null,
        reviewTime: null,
        reviewerId: null,
        notes: null,
        type: null,
        reviewerStatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加多级审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStuMultiLevelReview(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改多级审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStuMultiLevelReview(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStuMultiLevelReview(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除多级审核编号为"' + ids + '"的数据项？').then(function () {
        return delStuMultiLevelReview(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('routine/stuMultiLevelReview/export', {
        ...this.queryParams
      }, `stuMultiLevelReview_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
